package net.pimpas.visitor;

import net.pimpas.core.serviceprovider.ServiceProvider;
import net.pimpas.core.serviceprovider.ServiceProviderAnnotation;
import net.pimpas.core.visitor.BaseClassVisitor;
import net.pimpas.framework.PimpasFramework;
import net.pimpas.util.reflection.ReflectionUtil;

public final class ServiceProviderVisitor extends BaseClassVisitor {

	@SuppressWarnings("unchecked")
	@Override
	public void visitClass(Class clazz) {
		if(ReflectionUtil.isSubclass(clazz, ServiceProvider.class) && ReflectionUtil.checkAnnotationInClass(ServiceProviderAnnotation.class, clazz)) {
			ServiceProviderAnnotation spta = (ServiceProviderAnnotation) clazz.getAnnotation(ServiceProviderAnnotation.class);
			PimpasFramework.getCurrentInstance().registerServiceProvider(spta.serviceProviderType(), clazz);
		}
	}
}